#!/bin/bash

# ***************************************************************************
# * 
# * @file:build_mysql.sh 
# * @author:ebayboy@163.com 
# * @date:2019-11-05 09:52 
# * @version 1.0  
# * @description: Shell script 
# * @Copyright (c)  all right reserved 
#* 
#**************************************************************************/ 

ROOT_DIR=/usr/local/mysql


function build()
{
	rm -rf build && mkdir build && cd  build

	cmake3 ../ -DWITH_DEBUG=1 \
		-DCMAKE_INSTALL_PREFIX=$ROOT_DIR \
		-DMYSQL_DATADIR=$ROOT_DIR/data \
		-DWITH_BOOST=../boost \
		-DSYSCONFDIR=$ROOT_DIR/etc \
		-DEFAULT_CHARSET=utf8mb4 \
		-DDEFAULT_COLLATION=utf8mb4_general_ci \
		-DENABLED_LOCAL_INFILE=1 \
		-DEXTRA_CHARSETS=all || exit 1

	make -j4 || exit 1
	make install
}


function init_mysql()
{
	#初始化MySQL
	$ROOT_DIR/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

	#启动MySQL服务器 --skip-grant-tables 可以不使用密码登录MySQL，避免后续出现的
	$ROOT_DIR/bin/mysqld_safe --user=mysql --skip-grant-tables &

	#利用client连接
	$ROOT_DIR/bin/mysql -uroot -p --socket=/var/lib/mysql/mysql.sock
}

build;

init_mysql;

exit 0

